<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>课程辅导-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			
			<div class="weui-header bg-blue"> 
				<div class="weui-header-left"> <a href="<%=basePath %>/ls" class="icon icon-109 f-white">返回</a></div>
				<h1 class="weui-header-title">课程辅导记录</h1>
			    <div class="weui-header-right"><a href="<%=basePath %>/ls/course/coach/add" class="icon icon-36 f-white"> 添加</a></div> 
			</div>
			
	        <div class="weui_tab kcfd-list1" id="tab4">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item ">
	                    待辅导
	                </div>
	                <div class="weui_navbar_item" id="coached_item">
	                    已辅导
	                </div>
	                
	            </div>
	            <div class="weui_tab_bd">
			        <div class="weui_tab_bd_item borderNone">
			            <!--选项内容开始-->
			            <div class="weui_cells" id="coach_pending" style="margin: 0;">

						</div>
			            <!--选项内容结束-->
			            
			        </div>
			        <div class="weui_tab_bd_item borderNone">
			           <div id="coach_success">
			        	</div>
			        	<div class="dropload-down">
				        	<div class="loadData dropload-hasData">点击加载更多数据...</div>
				        </div>
			        </div>
			        
	            </div>
	        </div>
		</div>
		<script id="pendingCoach-table-template" type="text/x-handlebars-template">
			{{#each list}}
			<div class="weui_cells" style="margin: 0;">
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">姓名</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{studentName}}  {{gradeText}}（{{clazz}}）班</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">请假时间</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{twoDateFormat leaveStartTime leaveEndTime}}</p>
					</div>
				</div>
				<div>
					<div class="tcenter kcfd-btnWrap1">
						<a href="javascript:;" onclick="noCoach({{coachId}},'{{studentName}}')" class="linkBtn2 f14 fdBtn-no" style="margin: 30px">无需辅导</a>
						<a href="<%=basePath%>/ls/course/coach/add?leaveId={{leaveId}}" onclick="will_coach(this)" class="linkBtn2 f14 fdBtn-yes" style="margin: 30px">我要辅导</a>
					</div>
				</div>
			</div>
			{{/each}}
		</script>
		<script id="coached-table-template" type="text/x-handlebars-template">
			{{#each rows}}
			<div class="weui_cells" style="margin: 0 0 15px;">
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">学生姓名</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{studentName}}  {{gradeText}}（{{clazz}}）班</p>
					</div>
				</div>
				{{#equal coachType 1}}
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">请假时间</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{twoDateFormat leaveStartTime leaveEndTime}}</p>
					</div>
				</div>
				{{/equal}}
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">辅导类型</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{coachTypeText}}</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">辅导课程</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{subject}}</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">辅导老师</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{teacherName}}</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd" style="width: 120px;">辅导时间</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>{{dateFormat coachTime}}</p>
					</div>
				</div>
				{{#if coachResult}}
				<div class="weui_cell kcfd-listDetail">
					<div class="weui_cell_bd weui_cell_primary f15" style="line-height: 1.3em;">
						<p><span class="f17">辅导详情：</span>{{coachResult}}</p>
					</div>
				</div>
				{{/if}}
			</div>
			{{/each}}
		</script>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
	var isLoadAudited = false;
	var page = 1;
	var rows = 5;
	$(function() {
		$('#tab4').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
		loadCoachPending();
		$("#coached_item").click(function() {
			if(!isLoadAudited) loadCoachedList();
		})
		$(".dropload-hasData").click(function() {
			loadCoachedList();
		})
	});
	function noCoach(coachId, studentName) {
		$.confirm("确定" + studentName + "同学无需辅导?", "", function() {
			$.ajax({
		 		url : "<%=basePath%>/ls/course/coach/noCoach",
		 		type : "post",
		 		data : {
		 			id: coachId,
		 			coachStatus: '002'
		 		},
		 		dataType : "json",
		 		async : false,
		 		success : function(data) {
		 			if(data.code == '000') {
		 				$.toast("操作成功!");
		 				window.location.href = window.location.href+"?v="+new Date().getTime();
		 			}else {
		 				$.toast(data.msg, "cancel");
		 			}
		 		}, error:function(){
		 			$.toast("系统异常，请联系管理员",'forbidden');
	    		}
		 	});
		}, function() {
        	return;
        });
	}
	function loadCoachedList() {
		isLoadAudited = true;
		var params = {
			page: page,
  	 		rows: rows,
  	 		coachStatus: '000'
		};	            
       	$.ajax({
          	url : basePath + "/ls/course/coach/page/query",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : params,
            success: function(data){
            	 if(data.rows.length == 0 || params.page*params.rows >= data.total) {// 如果没有数据
            		 $("#coach_success").closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
                 	 if(data.rows.length == 0) return;
                 }
            	 loadCoachedHtml(data);
            	 page++;
            },
            error: function(xhr, type){
                 
               }
          });
	}
	function loadCoachPending() {
		$.ajax({
         	url : basePath + "/ls/course/coach/pending",
 	 		type : "post",
 	 		dataType : "json",
            success: function(data){
            	if(data != null && data.length > 0) {
            		var result = {};
            		result.list = data;
            		loadPendingCoachHtml(result);
            	}
             },
             error: function(xhr, type){
                 
             }
         });
	}
	function loadPendingCoachHtml(data){
		var myTemplate = Handlebars.compile($("#pendingCoach-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
			if(v1 == v2) {
				//满足添加继续执行
				return options.fn(this);
			}else {
				//不满足条件执行{{else}}部分
				return options.inverse(this);
			}
		});
		Handlebars.registerHelper("twoDateFormat", function(v1, v2) {
			return getTime(v1, "MM/dd hh:mm") + "-" + getTime(v2, "MM/dd hh:mm");
		});
		$('#coach_pending').append(myTemplate(data));
	}
	function loadCoachedHtml(data){
		var myTemplate = Handlebars.compile($("#coached-table-template").html());
		Handlebars.registerHelper("equal", function(v1,v2,options) {
			if(v1 == v2) {
				//满足添加继续执行
				return options.fn(this);
			}else {
				//不满足条件执行{{else}}部分
				return options.inverse(this);
			}
		});
		Handlebars.registerHelper("twoDateFormat", function(v1, v2) {
			return getTime(v1, "MM/dd hh:mm") + "-" + getTime(v2, "MM/dd hh:mm");
		});
		Handlebars.registerHelper("dateFormat", function(v1) {
			return getTime(v1, "yyyy/MM/dd hh:mm");
		});
		$('#coach_success').append(myTemplate(data));
	}
</script>

</body>
</html>